# _*_ coding:utf-8 _*_
# @Time : 2021/9/17 17:49
# @Author : wsl
# @File : Urllib
# @Project : python

import urllib.request
import urllib.parse

# https://www.baidu.com/s?wd=周杰伦&sex=男
# https://www.baidu.com/s?wd=%E5%91%A8%E6%9D%B0%E4%BC%A6


base_url = 'https://www.baidu.com/s?'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0'
}

data = {
    'wd': '周杰伦',
    'sex': '男'
}

new_data = urllib.parse.urlencode(data)
print(new_data)

url = base_url + new_data
# get请求方式的参数必须编码，参数是拼接到url后面
request = urllib.request.Request(url=url, headers=headers)
response2 = urllib.request.urlopen(request)
content2 = response2.read().decode('utf-8')
print(content2)
